package com.qfedu.controller;

import com.qfedu.common.JsonBean;
import com.qfedu.pojo.SysCar;
import com.qfedu.service.SysCarService;
import com.qfedu.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.font.EAttribute;

import java.util.List;

@Controller
@RequestMapping("/car")
public class SysCarController {

    @Autowired
    private SysCarService sysCarService;

    // 按租金排序
    @RequestMapping("/price.do")
    @ResponseBody
    public JsonBean selectByPrice(Integer getid){
        JsonBean bean = null;

        try {
            List<SysCar> list = sysCarService.findByPrice(getid);
            bean = JsonUtils.createJsonBean(1, list);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }
        return bean;
    }


    // 按热度排序
    @RequestMapping("/number.do")
    @ResponseBody
    public JsonBean selectByNumber(Integer getid){
        JsonBean bean = null;

        try {
            List<SysCar> list = sysCarService.findByNum(getid);
            bean = JsonUtils.createJsonBean(1, list);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0, e.getMessage());
        }
        return bean;
    }

    @RequestMapping("/findcar.do")
    @ResponseBody
    public JsonBean findCar(Integer getid){
        JsonBean bean=null;

        try {
            SysCar biId = sysCarService.findBiId(getid);
            bean = JsonUtils.createJsonBean(1, biId);
        }catch (Exception e){
            e.printStackTrace();
            bean= JsonUtils.createJsonBean(0, e.getMessage());
        }
        return bean;
    }
}